load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
load("//bazel:prost.bzl", "generated_files_check")

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "protos",
    srcs = glob(["proto/**/*.proto"]),
)

DEPENDENCIES = [
    # Keep sorted.
    "//rs/crypto/sha2",
    "//rs/nervous_system/canisters",
    "//rs/nervous_system/common",
    "//rs/nns/constants",
    "//rs/protobuf",
    "//rs/registry/keys",
    "//rs/registry/transport",
    "//rs/types/base_types",
    "//rs/types/types",
    "@crate_index//:candid",
    "@crate_index//:comparable",
    "@crate_index//:ic-cdk",
    "@crate_index//:ic-stable-structures",
    "@crate_index//:lazy_static",
    "@crate_index//:num-traits",
    "@crate_index//:prost",
    "@crate_index//:serde",
    "@crate_index//:serde_bytes",
    "@crate_index//:sha2",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/nns/common/protobuf_generator:lib",
    "//rs/test_utilities/compare_dirs",
    "@crate_index//:tempfile",
]

rust_library(
    name = "common",
    srcs = glob([
        "src/**/*.rs",
    ]),
    crate_name = "ic_nns_common",
    version = "0.9.0",
    deps = DEPENDENCIES,
)

rust_library(
    name = "common--test_feature",
    srcs = glob([
        "src/**/*.rs",
    ]),
    crate_features = ["test"],
    crate_name = "ic_nns_common",
    version = "0.9.0",
    deps = DEPENDENCIES,
)

generated_files_check(
    name = "check_generated_files",
    srcs = ["tests/check_generated_files.rs"],
    data = glob(["src/gen/**"]) + [
        ":protos",
        "//rs/types/base_types:protos",
    ],
    manifest_dir = "rs/nns/common",
    deps = DEV_DEPENDENCIES,
)

rust_test(
    name = "common_test",
    crate = ":common",
    deps = DEV_DEPENDENCIES,
)
